import { ElMessage } from 'element-plus'

interface ResponseData {
  code: number;
  msg: string;
  data?: any;
}

export const showMessage = (response: ResponseData) => {
  const { code, msg } = response
  
  if (code === 200) {
    ElMessage({
      message: msg || '操作成功',
      type: 'success',
      duration: 2000
    })
  } else {
    ElMessage({
      message: msg || '操作失败',
      type: 'warning',
      duration: 3000
    })
  }
}

export const showError = (error: any) => {
  ElMessage({
    message: error?.msg || '系统错误',
    type: 'error',
    duration: 3000
  })
}
